require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
if(!userInfo){
    location.href="/loginIndex"
}
var vm = new Vue({
    el:"#myInterest",
    data:{
        pop:{
            question: "确定要跳过此步骤？",
            show: false
        },
        categoryList:{},
        category:[],
        loginUid:userInfo.id,
        headImg:"",
        name:"",
        results:""
    },
    mounted:function(){
        // this.searchObject = this.getQueryStringArgs();
        // this.recruitId=this.searchObject&&this.searchObject.recruitId;
        // this.getRecruitById();
        //this.getUserLabel();
        this.getMainAllCategoryList();
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //获取所有自媒体分类信息
        getMainAllCategoryList:function(){
            var that=this;
            this.ajax({url:"/selfMedia/getMainAllCategoryList",dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.categoryList=b.json.data;
                }else{
                    vm.$refs.prompt.toast("获取分类信息列表失败！")
                }
            });

        },
        getLab:function(list,idx){
            var that=this;
            var spans=$("#centList"+idx).find("strong");
            if(spans.hasClass("myInterest-icon1")){
                spans.removeClass("myInterest-icon1");
                for(var i=0;i<=that.category.length;i++){
                    if(that.category[i]==list.categoryId){
                        that.category.splice(i,1)
                    }
                }
            }else{
                spans.addClass("myInterest-icon1");
                that.category.push(list.categoryId);
            }
            console.log(spans);
            console.log(that.category)
        },
        //增加自媒体用户分类信息
        addUserCategory:function(){
            var that=this;
            var data={
                loginUid:userInfo.id,
                categoryId:that.category.join("&")
            };
            //data.categoryId=category;
            this.ajax({url:"/selfMedia/addUserCategory",data:data,dataType:"json",traditional:true,method:"post"},function(b){
                if(b.json.code==0){
                    that.getNext();
                }else{
                    vm.$refs.prompt.toast("提交失败！")
                }
            });

        },
        //退货显示框
        getIsClassify:function(){
            this.pop.show=!this.pop.show;
        },
        getNext:function(){
            location.href="/";
        }
    },
    watch:{

    }
});
//去掉所有空格
function Trim(str) {
    var result;
    result = str.replace(/\s+/g," ");
    // if(is_global==1){
    //     result = result.replace(/\s/g,"");
    // }
    return result.replace(/(^\s*)|(\s*$)/g,"");
}